package org.jproxy.json;

public class JSONAttribute
{
	private String name;
	private String value;
	private JSONObject jsonObject;

	JSONAttribute(String name, String value)
	{
		this.name = name;
		this.value = value;
	}

	JSONAttribute(String name, JSONObject jsonObject)
	{
		this.name = name;
		this.jsonObject = jsonObject;
	}

	public String getName()
	{
		return name;
	}

	public String getValue()
	{
		return value;
	}

	@SuppressWarnings("unchecked")
	public <T> T getValue(Class<T> clazz)
	{
		Object result =  null;
		if(String.class.equals(clazz))
			result = value;
		else if(int.class.equals(clazz) || Integer.class.equals(clazz))
			result = new Integer(value);
		else if(long.class.equals(clazz) || Long.class.equals(clazz))
			result = new Long(value);
		else if(float.class.equals(clazz) || Float.class.equals(clazz))
			result = new Float(value);
		else if(double.class.equals(clazz) || Double.class.equals(clazz))
			result = new Double(value);
		else if(boolean.class.equals(clazz) || Boolean.class.equals(clazz))
			result = new Boolean(value);
		return (T) result;
	}

	public JSONObject getJSONObject()
	{
		return jsonObject;
	}
}
